
<style>
    *{margin: 0;padding: 0;list-style: none;}
    .imglist{width: 100%;overflow: hidden;margin-bottom: 20px;}
    .imglist h3{font-size: 16px;color:#333;margin-bottom: 20px;}
    .imglist li{width:200px;float: left;margin-right: 10px;margin-bottom: 10px;}
    .imglist li h4{height: 100px;}
    .imglist li h4 img{width: 100%;height: 100%;}
</style>

<ul class="imglist" id="cutting">
    <h3>已裁切的图片</h3>
    {volist name="routeInfoImgList" id="vo"}
        {if condition="$vo.scene eq 1"}
            <li mid="{$vo.id}">
                <h4><img src="{$vo.m_path}"/></h4>
                <input type="checkbox" class="ch">
            </li>
        {/if}
    {/volist}

    <button onclick="sub_cut();">提交</button>

</ul>

<ul class="imglist" id="original">
    <h3>未裁切的原图</h3>
    {volist name="routeInfoImgList" id="vo"}
        {if condition="$vo.scene eq 0"}
            <li mid="{$vo.id}">
                <h4><img src="{$vo.m_path}" /></h4>
                <input type="checkbox" onclick="sub_ori('{$vo.id}',this,'{$vo.m_path}');" class="ch">
            </li>
        {/if}
    {/volist}
    <button onclick="sub_1();">提交</button>
</ul>

<input name="mid" value="" type="hidden" id="mid"/>
<input name="img" value="" type="hidden" id="img"/>
<img src="" id="c_img" style="display: none"/>
<script>
    var route_info_id="{$route_info_id}";
    var pid="{$pid}";
    var day_no="{$day_no}";

   /* alert(route_info_id);
    alert(pid);
    alert(day_no);
*/

   function sub_ori(id,obj,s_img){
      if($(obj).is(":checked")){
         $("#mid").val(id);
          $("#img").val(s_img);
          $(obj).parents("li").siblings().find(".ch").removeAttr("checked");
      }
       var count=0;
      $("#original li").each(function(){
          if($(this).find(".ch").is(":checked")){
              count++;
          }
      });
       if(count==0){
           $("#mid").val("");
           $("#img").val("");
       }
   }

    function sub_1(){
        var str=$("#mid").val();
        var img=$("#img").val();

        $("#c_img").attr("src",img);

        var width=$("#c_img").width();
        var height=$("#c_img").height();
        //alert(width);
        if(width<450 || height<270){
            alert("所选原图宽不得小于450,高不得小于270");
            return;
        }
        if(str==""){
            alert("请选择图片");
            return;
        }else{

            var flag=1;
            var url="/add_img.php?p_id="+pid+"&tr_id="+route_info_id+"&tri_id="+day_no+"&flag="+flag+"&img="+img;
            // alert(url);
            layer.open({
                type: 2,
                title:"裁切图片",
                shift: 2,
                area: ['100%', '100%'],
                content: [url],
                scrollbar: true ,//屏蔽浏览器滚动条

            });


        }

    }





    function sub_cut(){
       var str="";
        $("#cutting li").each(function(){
            var mid=$(this).attr("mid");
           if($(this).find(".ch").is(":checked")) {
               str=str+"|"+mid;
           }
        });
        if(str==""){
            alert("请选择图片");
            return;
        }else{
            str= str.substr(1);
            $.ajax({
                type:'get',
                dataType:'json',
                url:"/admin/product/product_gallery_cut",
                data:{"str":str,"pid":pid,"route_info_id":route_info_id},
                success:function(data){
                    if(data.status==1){
                        window.parent.location.reload();
                    }else{
                        alert(data.message);
                    }
                }
            })
        }
    }





</script>

